<%@ page contentType="text/html; charset=UTF-8"%>
<%@page import="com.sinodata.bsm.common.vo.Attribute"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
	Attribute attribute =(Attribute) request.getAttribute("attribute");
 %>
<html>
  <head>
    
    <title>修改属性</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta http-equiv="pragma" content="no-cache"/>
	<meta http-equiv="cache-control" content="no-cache"/>
	<meta http-equiv="expires" content="0"/>  
	<%@ include file="../include/taglib.jsp"%>
	<%@ include file="../include/common.jsp"%>
	<%@ include file="../include/form.jsp"%>
	<style type="text/css">
		.td_left{
			width:100px;
		}
	</style>
	
	<script type="text/javascript">
		$(document).ready(function(){
		
			$.formValidator.initConfig({
				formid:"attributeForm",
				onerror:function(msg){},
				onsuccess:function(){
				    	var entity = $('#attributeForm').serialize();
						var pauseWindow = getTopWin(window).currentWin['updateAttributeWindow'];
						pauseWindow.update(entity);
						getTopWin(window).closejBox('updateAttributeWindow');
						return false;
				}
			});
			
			$("#name").formValidator({onshow:"请输入属性名称",onfocus:"属性名称最大长度为40",onempty:"属性名称不能为空"})
					  .inputValidator({min:1,onerror:"属性名称不能为空"})
			          .functionValidator({
					  	  fun:function(val,elem){
					  	  	 if(val.length>40){
					  	  	 	return "属性名称长度输入有误";
					  	  	 }
					  	  	 	return true;
					  	  }
					  })
					  .ajaxValidator({
					    dataType:"json",
					  	type:"get",
					  	async : true,
					  	url:"attribute!repeatNameValidate.action?resId=${resId}&id=${attribute.id}",
					  	success:function(data){
					  		if(data=='true'){
					  			return false;
					  		}
					  			return true;
					  	},
					  	error:function(jqXHR, textStatus, errorThrown){
					  		getTopWin(window).getMessageBox().alert('验证属性名称重复时出错！'+textStatus,'错误');
					  	},
					  	buttons: $("input[type='submit']"),
					  	onerror:"属性名称已重复",
					  	onwait : "正在对属性名称进行重复性校验，请稍候..."
					  });
			$("#dataUnit").formValidator({onshow:"数据类型为数值型时可填",onfocus:"数据单位可以为空",empty:true,onempty:"输入正确"})
			          .inputValidator({min:1,max:5, onerror:"数据单位长度输入有误"});
			$("#desc").formValidator({onshow:"最多只能输入150个字符",onfocus:"属性描述可以为空",empty:true,onempty:"输入正确"})
			          .inputValidator({min:1,max:150, onerror:"属性描述长度有误"})
			          .functionValidator({
					  	  fun:function(val,elem){
					  	  	 if(val.length>150){
					  	  	 	return "属性描述长度输入有误";
					  	  	 }
					  	  	 	return true;
					  	  }
					  });
			          
			var validateInfo = "${validate.flag}";
			if(validateInfo=='false'){
				getTopWin(window).getMessageBox().tip('${validate.info}', 'info'); 
			}
			
			$("#name").blur();
	    });	
	
		function cancel(){
			getTopWin(window).closejBox('inputAttributeWindow');
		}
		
		//验证是否删除
		function isDel(id){
			var isFlag = false;
			$.ajax({
					type:'post',
					url:'attribute!isDelete.action',
					data:{id:id},
					global:false,
					async:false,
					cache:false,
					dataType:'json',
					success:function(data,textStatus){
						isFlag = data;
					},
					error:function(){
						getTopWin(window).getMessageBox().alert('检验属性是否删除出错!','错误');
					}
			});
			return isFlag;
		}
		
	</script>
  </head>
  
  <body style="padding:5px;">
    <form action=""  method="post" id="attributeForm" name="attributeForm">
    	<table class="table_eidt" id="attributeTbl">
    		<tbody>
				<tr>
					<td class="td_left" ><font color="red">*</font> 属性名称</td>				
					<td class="td_right" >
						<input type="text" class="input_text" name="name" id="name" value="${attribute.name}" />
						<span id="nameTip"></span>
						<input type="hidden" name="id" value="${attribute.id}" />
					</td>				
				</tr>
				<tr>
					<td class="td_left" >数据类型</td>
					<td class="td_right" >
						<select id="dataTypeId" name="dataTypeId" onchange="if(this.value==2){$('#dataUnit').removeAttr('disabled');}else{$('#dataUnit').attr('disabled','disabled');}$('#dataUnit').val('');"   >
							<c:forEach var="dataType" items="${dataTypes}" >
								<option   ${dataType.id==attribute.dataTypeId?"selected='selected'":""}  value="${dataType.id}">${dataType.name}</option>
							</c:forEach>
						</select>
					</td>
				</tr>
				<tr id="dataUnitTr" style="${attribute.dataUnit==2?'display:none;':''}">
					<td class="td_left" >数据单位</td>
					<td class="td_right" >
						<input type="text"  class="input_text" value="${attribute.dataUnit}" name="dataUnit" id="dataUnit" maxlength="5"/>
						<span id="dataUnitTip"></span>
					</td>
				</tr>
				<tr>
					<td class="td_left" >数据格式</td>
					<td class="td_right" >
						<input type="text" class="input_text" name="format" id="format" maxlength="50" value="${attribute.format}"/>
					</td>	
				</tr>
				<tr>
					<td class="td_left" >属性描述</td>
					<td class="td_right">
						<textarea rows="3" cols="28" name="desc" id="desc" onkeyup="this.value=this.value.substring(0,150)" style="border:1px solid #c0c0c0;" >${attribute.desc}</textarea>
						<span id="descTip"></span>
					</td>
				</tr>
			</tbody>
    	</table>
    	
    	<div class="btn-div" >
    		<input type="submit"  class="btn-4" value="保存" />
			<input type="button"  class="btn-4" value="取消" onclick="cancel()" />
    	</div>
    </form>
  </body>
</html>
